cmake_minimum_required(VERSION 3.10)
get_filename_component(PRJ_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${PRJ_NAME} VERSION 1.0.0)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_compile_options(
        #        -Wall -Wextra -pedantic -Werror
        -Wall
)

configure_file("${PROJECT_NAME}Config.h.in" "${PROJECT_NAME}Config.h"
        ESCAPE_QUOTES
        NEWLINE_STYLE UNIX
        )

add_executable(${PROJECT_NAME}
        ${PROJECT_NAME}Config.h.in
        main.cpp
        Log.h
        Utils.cpp Utils.h
        )


#message("${CMAKE_SOURCE_DIR}")
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_BINARY_DIR})
#target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_SOURCE_DIR})

#set(CMAKE_VERBOSE_MAKEFILE TRUE)
#set(CMAKE_COLOR_MAKEFILE TRUE)

FILE(GLOB subprojects RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/subproject
        ${CMAKE_CURRENT_SOURCE_DIR}/subproject/*
        )

set(WINBUILD_HOME "$ENV{WINBUILD_ROOT}")

if (WIN32)
    message("Build on windows...")
    set(exclude_projects
            SDLMusicPlayer
#            OggAnalyzer
#            AudioMixer
#            G711Codec
            )
    add_compile_options(
            #            https://wintermade.it/blog/posts/__attribute__packed-on-windows-is-ignored-with-mingw.html
            -mno-ms-bitfields
    )
    set(OGG_INCLUDE_DIRS "${WINBUILD_HOME}/include")
    set(OGG_LIBRARY_DIRS "${WINBUILD_HOME}/lib64")
    set(OGG_LIBRARIES "ogg")

    set(OPUS_INCLUDE_DIRS "${WINBUILD_HOME}/include/opus")
    set(OPUS_LIBRARY_DIRS "${WINBUILD_HOME}/lib64")
    set(OPUS_LIBRARIES "opus")

    #    set(OPUSFILE_HOME "D:/grocery/winbuild_mirror/1.5.0/packages/source_packages/opusfile-0.12")
#    set(OPUSFILE_HOME "C:/Users/guoshunw/CLionProjects/opusfile")
    set(OPUSFILE_HOME "${CMAKE_CURRENT_SOURCE_DIR}/opusfile")
    set(OPUSFILE_INCLUDE_DIRS "${OPUSFILE_HOME}/include")
    set(OPUSFILE_LIBRARY_DIRS "${OPUSFILE_HOME}/cmake-build-debug")
    set(OPUSFILE_LIBRARIES opusfile)

elseif (APPLE)
    message("Build on apple...")
elseif (UNIX)
    message("Unix like OS")
endif ()

foreach (subproject ${subprojects})
    list(FIND exclude_projects ${subproject} index)
    if (NOT index EQUAL -1)
        continue()
    endif ()
    message("add sub project: ${subproject}")

    add_subdirectory(subproject/${subproject})
    target_include_directories(${PROJECT_NAME} PUBLIC subproject/${subproject})
    target_link_libraries(${PROJECT_NAME} ${subproject})

endforeach ()

